package 剑指offer;

import java.util.ArrayList;

/**
 * Created by yang on 2016/8/24.
 */
public class FindNodeFromKofCountBackwards {
    public ListNode FindKthToTail(ListNode head,int k) {
        ArrayList<ListNode> arrayList = new ArrayList<ListNode>();

        ListNode nodeOfk = head;

        if(head == null)
            return null;

        while(head != null) {
            head = head.next;
            arrayList.add(head);
        }

        int size = arrayList.size();
        int end = size - k;

        for(int i = 0; i <= end; i++) {
            nodeOfk = nodeOfk.next;
        }

        return nodeOfk;
    }
}

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
